/**
 *
 */
package com.kandinfo.survey.common.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.kandinfo.base.common.dto.ResultDto;
import com.kandinfo.base.security.SecurityContext;
import com.kandinfo.base.security.domain.User;
import com.kandinfo.survey.common.dto.PatientInfoDto;
import com.kandinfo.survey.common.service.PatientInfoService;

/**
 * 病人初次就诊信息管理Controller
 * 
 * @author tangqh
 */
@Controller
@RequestMapping(value = "/weixin/patientinfo")
public class PatientInfoController {

    @Autowired
    PatientInfoService patientInfoService;

    /**
     * 病人补充初次就诊信息页面
     */
    @RequestMapping(value = "/my-patient-info", method = RequestMethod.GET)
    public String fillInfo(Model model) {
        // get info if exists
        User curUser = SecurityContext.getInstance().getCurrentUser();
        model.addAttribute("patientInfoDto", patientInfoService.findByPatientId(curUser.getId()));
        return "/patient/patientinfo/patient-info";
    }

    /**
     * 病人初次就诊信息保存
     * 
     * @return
     */
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    public ResultDto save(@RequestBody PatientInfoDto patientInfoDto) {
        return patientInfoService.saveByDto(patientInfoDto);
    }
    
    /**
     * 病人初次就诊信息保存
     * 
     * @return
     */
    @RequestMapping(value = "/get", method = RequestMethod.POST)
    public PatientInfoDto get(@RequestBody Long patientId) {
        return patientInfoService.findByPatientId(patientId);
    }

}
